package com.dc.seckill.dao;

import com.dc.seckill.domain.MiaoshaOrder;
import com.dc.seckill.domain.OrderInfo;
import org.apache.ibatis.annotations.*;

/**
 * @模块 秒杀模块
 * @作者 djs
 * @时间 2018/3/22 8:57
 * @版本 V1.0
 * @描述 对订单信息进行操作
 */
@Mapper
public interface OrderDao {

    /**
     * 获取秒杀订单
     * @params [userId, goodsId]
     * @returns com.dc.seckill.domain.MiaoshaOrder
     */
    @Select("select * from miaosha_order m where m.user_id=#{userId} and m.goods_id=#{goodsId}")
    MiaoshaOrder queryOrderByUserIdGoodsId(@Param("userId") Long userId, @Param("goodsId") Long goodsId);

    @Insert( "insert into order_info(user_id, goods_id, goods_name, goods_count, goods_price, order_channel, status, create_date)values("
            + "#{userId}, #{goodsId}, #{goodsName}, #{goodsCount}, #{goodsPrice}, #{orderChannel},#{status},#{createDate} )")
    @Options(keyProperty="id",keyColumn="id",useGeneratedKeys=true)
// @SelectKey(keyColumn="id", keyProperty="id", resultType=long.class, before = false, statement="select last_insert_id()")
    long insert(OrderInfo orderInfo);

    @Insert("insert into miaosha_order (user_id, goods_id, order_id)values(#{userId}, #{goodsId}, #{orderId})")
    int insertMiaoshaOrder(MiaoshaOrder miaoshaOrder);
}